package com.appserver.resource.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Created by guoyanjiang on 2018-12-19.
 */
@Aspect
@Component
public class HttpTimeCostAspect {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Around("execution(* com.appserver.resource.HttpResource..*(..))")
    public Object feignService(ProceedingJoinPoint point) throws Throwable {

        logger.info("start call url {}", point.getArgs()[0]);
        long start = System.currentTimeMillis();
        try {
            return point.proceed();
        }finally {
            long end = System.currentTimeMillis();
            logger.info("end call url {}, cost time {} ms", point.getArgs()[0], end - start);
        }
    }
}
